import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_swiper/flutter_swiper.dart';
import 'package:kxy_flutter_app/model/exam_question.dart';
import 'package:kxy_flutter_app/view/examination/widget/question_result_card_widget.dart';
import 'package:kxy_flutter_app/view/examination/widget/question_swiper_widget.dart';
import 'widget/question_header_widget.dart';

class QuestionReviewView extends StatefulWidget {
  final List<Question> quesList;

  const QuestionReviewView({Key key, this.quesList}) : super(key: key);

  @override
  State<StatefulWidget> createState() {
    return _QuestionReviewViewState();
  }
}

class _QuestionReviewViewState extends State<QuestionReviewView> {
  int index = 0;
  SwiperController swiperCtrl = new SwiperController();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      appBar: AppBar(
        title: Text('试题解析'),
        elevation: 0,
        actions: [
          FlatButton(
            child: Text('答题卡'),
            onPressed: () {
              showDialog(
                context: context,
                builder: (cxt) {
                  return QuestionResultCardWidget(
                    onSelect: (index) => swiperCtrl.move(index, animation: false),
                    quesList: widget.quesList,
                  );
                },
              );
            },
          ),
        ],
      ),
      body: Column(
        children: [
          QuestionHeaderWidget(
            index: index,
            question: widget.quesList[index],
            total: widget.quesList.length,
          ),
          Expanded(
            child: QuestionSwiperWidget(
              onChangeIndex: (i) {
                setState(() {
                  this.index = i;
                });
              },
              swiperCtrl: swiperCtrl,
              questionList: widget.quesList,
              setAnswer: (answer) => {},
              withResult: true,
            ),
          ),
        ],
      ),
    );
  }

  Widget bottomBar() {
    return Container(
      height: 50,
      child: Row(
        children: [
          GestureDetector(
            onTap: swiperCtrl.previous,
            child: Container(
              decoration: decoration,
              child: Text('上一题', style: labelStyle),
            ),
          ),
          GestureDetector(
            onTap: swiperCtrl.next,
            child: Container(
              decoration: decoration,
              child: Text('下一题', style: labelStyle),
            ),
          ),
        ],
      ),
    );
  }

  TextStyle get labelStyle {
    return TextStyle(
      color: Colors.white,
    );
  }

  Decoration get decoration {
    return BoxDecoration(
      color: Theme.of(context).primaryColor,
    );
  }
}
